<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象</title>
</head>
<body>
<p>点击下面的按钮，循环遍历对象 "person" 的属性。</p>
<button onclick="myFunction()">点击这里</button>
<script>
    function person(firstname,lastname,age,eyecolor) {
        this.firstname=firstname;
        this.lastname=lastname;
        this.age=age;
        this.eyecolor=eyecolor;
    }
    myfather=new person("bill","gates",56,"blue");
    document.write(myfather.firstname+"is"+myfather.age+"years old");

    function myFunction()
    {
        var x;
        var txt="";
        var person={fname:"Bill",lname:"Gates",age:56};

        for (x in person)
        {
            txt=txt + person[x];
        }

        document.getElementById("demo").innerHTML=txt;
    }
</script>
</body>
</html>